package com.ruoyi.common.utils;


import com.ruoyi.common.constant.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.io.*;
import java.util.Base64;

/**
 * 描述:
 *
 * @author 刘松山
 * @date 2021/11/28 20:31
 */
public class Base64Convert {
    private static final Logger LOGGER = LoggerFactory.getLogger(Base64Convert.class);

    /**
     * @Description： 图片转化成base64字符串
     * @param: path
     * @Return:
     */
    public static String GetImageStr(String path) {
        //将图片文件转化为字节数组字符串，并对其进行Base64编码处理
        //待处理的图片
        String base64 ="";
        try {
            String imgFile = Constants.IMG_URL + path;
            InputStream is = new FileInputStream(new File(imgFile));//从磁盘读取照片
            int length = is.available();
            byte[] buffer = new byte[length];
            is.read(buffer);
              base64 = Base64.getEncoder().encodeToString(buffer);


        }catch (IOException e) {
            e.printStackTrace();
        }
        //返回Base64编码过的字节数组字符串
        return base64;
    }

    public static void main(String[] args) throws Exception {
     System.out.println(GetImageStr(""));
    }
}
